<?php 
	include("header.php");
	include("top_menu.php");
	$type_id = $_POST['type_id'];
	$place = $_POST['place'];
	$info = $_POST['info'];
	$lat = 0.0;
	$lng = 0.0;
	$connection = mysql_pconnect("localhost" , "root" , "31122001");
    mysql_select_db("kt_site");

    mysql_query("SET NAMES utf8");
    $xml = simplexml_load_file('http://maps.google.com/maps/api/geocode/xml?address='.$place.'&sensor=false');
    echo $xml;
    $status = $xml->status;
    if ($status == 'OK') {
    	$lat = $xml->result->geometry->location->lat;
		$lng = $xml->result->geometry->location->lng;
    }
    
    $query = "INSERT INTO devices(type_id, place, longitude, latitude, info) VALUES ($type_id, '$place', $lng, $lat , '$info');";
	$result = mysql_query($query);
	echo "<meta http-equiv='Refresh' content='0; URL=index.php'>";
	exit;
?>
